/**
 * \file TestCollatz.h
 * \author Augustine Mathew 
 * \author Rusty Fausk
 * \date 6/9/2009
 * \brief Test suite
 * 
 * This file contains the test suite for testing int eval(int, int) in main.c++
 */    

#ifndef TestCollatz_h
#define TestCollatz_h

// --------
// includes
// --------

#include <sstream> // istringtstream, ostringstream
#include <string>  // ==

#include "cppunit/TestFixture.h"             // TestFixture
#include "cppunit/extensions/HelperMacros.h" // CPPUNIT_TEST, CPPUNIT_TEST_SUITE, CPPUNIT_TEST_SUITE_END

using namespace CppUnit;

// -----------
// TestCollatz
// -----------
/**
 * \brief Test framework
 * 
 * 
 * A small test framework to test 3n+1 Problem as specified on UVA
 */
struct TestCollatz : TestFixture {
    // ----
    // read
    // ----

    void test_read () {
        std::istringstream in("1 10\n");
        bool b = read(in);
        CPPUNIT_ASSERT(b == true);
        CPPUNIT_ASSERT(i ==    1);
        CPPUNIT_ASSERT(j ==   10);
        }
	
	void test_read1 () {
        std::istringstream in("11 10\n");
        bool b = read(in);
        CPPUNIT_ASSERT(b == true);
        CPPUNIT_ASSERT(i ==   11);
        CPPUNIT_ASSERT(j ==   10);
        }
	
	void test_read2 () {
        std::istringstream in("123 12340\n");
        bool b = read(in);
        CPPUNIT_ASSERT(b ==   true);
        CPPUNIT_ASSERT(i ==    123);
        CPPUNIT_ASSERT(j ==  12340);
        }
	
	void test_read3 () {
        std::istringstream in("5654 5654\n");
        bool b = read(in);
        CPPUNIT_ASSERT(b == true);
        CPPUNIT_ASSERT(i == 5654);
        CPPUNIT_ASSERT(j == 5654);
        }
	
    // ----
    // eval
    // ----

    void test_eval1 () {
        i =  1;
        j = 10;
        v =  0;
        eval();
        CPPUNIT_ASSERT(v == 20);}

    void test_eval2 () {
        i = 100;
        j = 200;
        v =   0;
        eval();
        CPPUNIT_ASSERT(v == 125);}

    void test_eval3 () {
        i = 201;
        j = 210;
        v =   0;
        eval();
        CPPUNIT_ASSERT(v == 89);}

    void test_eval4 () {
        i =  900;
        j = 1000;
        v =    0;
        eval();
        CPPUNIT_ASSERT(v == 174);}

    void test_eval5 () {
        i = 999900;
        j = 999999;
        v =    0;
        eval();
        CPPUNIT_ASSERT(v == 259);}
	
	void test_eval6() {
		i = 1;
		j = 1;
		v = 0;
		eval();
		CPPUNIT_ASSERT(v == 1);}

	void test_eval7() {
		i = 210;
		j = 201;
		v = 0;
		eval();
		CPPUNIT_ASSERT(v == 89);}
	
	void test_eval10(){
	int v = eval (7037,3805);
	CPPUNIT_ASSERT(v == 262);
	}


	void test_eval11(){
	int v = eval (3522,2838);
	CPPUNIT_ASSERT(v == 217);
	}


	void test_eval12(){
	int v = eval (2747,806);
	CPPUNIT_ASSERT(v == 209);
	}


	void test_eval13(){
	int v = eval (7534,3357);
	CPPUNIT_ASSERT(v == 262);
	}


	void test_eval14(){
	int v = eval (3205,168);
	CPPUNIT_ASSERT(v == 217);
	}


	void test_eval15(){
	int v = eval (1198,4397);
	CPPUNIT_ASSERT(v == 238);
	}


	void test_eval16(){
	int v = eval (3529,7742);
	CPPUNIT_ASSERT(v == 262);
	}


	void test_eval17(){
	int v = eval (2138,1644);
	CPPUNIT_ASSERT(v == 180);
	}


	void test_eval18(){
	int v = eval (864,2763);
	CPPUNIT_ASSERT(v == 209);
	}


	void test_eval19(){
	int v = eval (3744,6129);
	CPPUNIT_ASSERT(v == 236);
	}
	
	void test_eval20(){
		int v = eval (1,1);
		CPPUNIT_ASSERT(v == 1);
	}

    // -----
    // print
    // -----

    void test_print () {
        i =  1;
        j = 10;
        v = 20;
        std::ostringstream out;
        print(out);
        CPPUNIT_ASSERT(out.str() == "1 10 20\n");}

    // -----
    // suite
    // -----

    CPPUNIT_TEST_SUITE(TestCollatz);
    CPPUNIT_TEST(test_read);
    CPPUNIT_TEST(test_read1);
    CPPUNIT_TEST(test_read2);
    CPPUNIT_TEST(test_read3);
    CPPUNIT_TEST(test_eval1);
    CPPUNIT_TEST(test_eval2);
    CPPUNIT_TEST(test_eval3);
    CPPUNIT_TEST(test_eval4);
    CPPUNIT_TEST(test_eval5);
    CPPUNIT_TEST(test_eval6);
    CPPUNIT_TEST(test_eval7);
    CPPUNIT_TEST(test_read);
    CPPUNIT_TEST(test_eval10);
    CPPUNIT_TEST(test_eval11);
    CPPUNIT_TEST(test_eval12);
    CPPUNIT_TEST(test_eval13);
    CPPUNIT_TEST(test_eval14);
    CPPUNIT_TEST(test_eval15);
    CPPUNIT_TEST(test_eval16);
    CPPUNIT_TEST(test_print);
    CPPUNIT_TEST_SUITE_END();};

#endif // TestCollatz_h
